package com.luochen.cdpt.repository;

import com.luochen.cdpt.eneity.Policy;
import com.luochen.cdpt.eneity.QEmpInfo;
import com.luochen.cdpt.eneity.QPolicy;
import com.querydsl.core.types.dsl.StringPath;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer;
import org.springframework.data.querydsl.binding.QuerydslBindings;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

/**
 * @Auther: star
 * @Date: 2019/1/12 11:13
 * @Description:
 */
@RepositoryRestResource(path = "/policy")
public interface IPolicyRepository extends PagingAndSortingRepository<Policy, String>,
        QuerydslPredicateExecutor<Policy>, JpaSpecificationExecutor<Policy>,
        QuerydslBinderCustomizer<QPolicy> {

    default void customize(QuerydslBindings bindings, QPolicy qPolicy) {
        bindings.bind(qPolicy.orderid,qPolicy.areaname,qPolicy.inscompanyname,qPolicy.csalecde,qPolicy.orgname).first(
                (StringPath path, String value) -> path.contains(value));
        //待结算金额处理
        bindings.bind(qPolicy.djsfee).first((path, value) -> {
            if(value==0){
                return  path.notIn(value);
            }
            return path.eq(value);
        });
    }

}
